<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
            "http://www.w3.org/TR/REC-html40/loose.dtd">
<HTML>
<HEAD>



<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<META name="GENERATOR" content="hevea 1.08">
<LINK rel="stylesheet" type="text/css" href="tutorial.css">
<TITLE>
Modelling
</TITLE>
</HEAD>
<BODY >
<A HREF="tutorial055.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="tutorial053.html"><IMG SRC ="contents_motif.gif" ALT="Up"></A>
<A HREF="tutorial057.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
<HR>

<H2 CLASS="section"><A NAME="htoc117">8.3</A>&nbsp;&nbsp;Modelling</H2>
The problem modelling code must:
 <UL CLASS="itemize"><LI CLASS="li-itemize">
 Create the variables with their initial domains
 <LI CLASS="li-itemize">Setup the constraints between the variables
 </UL>
A simple example is the &#8220;crypt-arithmetic&#8221; puzzle, 
<CODE>SEND+MORE = MONEY</CODE>.
The idea is to associate a digit (0-9) with each letter so that the
equation is true. The ECL<SUP><I>i</I></SUP>PS<SUP><I>e</I></SUP> code is as follows:<BR>
<BR>
<A NAME="send-more-money"></A>

	<TABLE CELLPADDING=10>
<TR><TD BGCOLOR="#CCCCFF">
	<BLOCKQUOTE CLASS="quote"><PRE>
:- lib(ic).

sendmore(Digits) :-
    Digits = [S,E,N,D,M,O,R,Y],

% Assign a finite domain with each letter - S, E, N, D, M, O, R, Y - 
% in the list Digits
    Digits :: [0..9],

% Constraints
    alldifferent(Digits),
    S #<CODE>\</CODE>= 0,
    M #<CODE>\</CODE>= 0,
                 1000*S + 100*E + 10*N + D
               + 1000*M + 100*O + 10*R + E
    #= 10000*M + 1000*O + 100*N + 10*E + Y,

% Search
    labeling(Digits).
</PRE></BLOCKQUOTE></TD>
</TR></TABLE><BR>
<HR>
<A HREF="tutorial055.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="tutorial053.html"><IMG SRC ="contents_motif.gif" ALT="Up"></A>
<A HREF="tutorial057.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
</BODY>
</HTML>
